import { Injectable } from '@angular/core';
import { RouterModule, Routes,CanActivateChild,Router,ActivatedRouteSnapshot,RouterStateSnapshot } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { DashboardComponent } from "./dashboard/dashboard.component";
import {PageComponent} from "./page.component";
import { MemberComponent } from "./member/member.component";
//import {TopComponent} from "./monitor/electricity/top/top.component";

//登录验证，根据isLogin判断路由是否可以被激活,组件是否需要加载
@Injectable()
export class CanActivateTeam implements CanActivateChild {
  constructor(private router: Router) { }
  canActivateChild(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ) {
    if (!(localStorage.getItem("isLogin"))) {
      this.router.navigateByUrl('login');
      return false;
    }
    return true;
  }
}

export const routes = [
  { path: 'login',loadChildren: './login/login.module#LoginModule'},
  //{ path: 'top/:data', component: TopComponent },
  //{ path: 'demo/:data',  loadChildren: './demo/demo.module#DemoModule' },
  {
    path: 'page',
    canActivateChild: [CanActivateTeam],
    component:PageComponent,
    children:[
      { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
      { path: 'dashboard',  component: DashboardComponent },
      { path: 'member',  component: MemberComponent },
      { path: 'operation',loadChildren: './operation/operation.module#OperationModule' },
      { path: 'groupmanagement',loadChildren: './groupmanagement/groupmanagement.module#GroupmanagementModule' },
      { path: 'ordermanagement', loadChildren: './ordermanagement/ordermanagement.module#OrdermanagementModule' },
      { path: 'productmanagement', loadChildren: './productmanagement/productmanagement.module#ProductmanagementModule' },
      { path: 'usermanagement', loadChildren: './usermanagement/usermanagement.module#UsermanagementModule' },
      { path: 'accountfundsmanagement', loadChildren: './accountfundsmanagement/accountfundsmanagement.module#AccountfundsmanagementModule' },
      { path: 'sysmanagement', loadChildren: './sysmanagement/sysmanagement.module#SysmanagementModule' }

    ]
  }
];

export const PageRoute: ModuleWithProviders = RouterModule.forChild(routes);

